package com.example.myapplication;

import android.annotation.SuppressLint;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class Selectseat extends AppCompatActivity {

    private Button btn_xuanzuo;
    private Button btn_xuanpian;
    private TextView txt_xunzuo;
    private CheckBox checkbox1;
    private CheckBox checkbox2;
    private CheckBox checkbox3;
    private CheckBox checkbox4;
    private CheckBox checkbox5;
    private CheckBox checkbox6;
    private CheckBox checkbox7;
    private CheckBox checkbox8;
    private CheckBox checkbox9;
    private CheckBox checkbox10;
    private CheckBox checkbox11;
    private CheckBox checkbox12;
    private CheckBox checkbox13;
    private CheckBox checkbox14;
    private CheckBox checkbox15;
    private CheckBox checkbox16;
    private CheckBox checkbox17;
    private CheckBox checkbox18;
    private CheckBox checkbox19;
    private CheckBox checkbox20;
    private CheckBox checkbox21;
    private CheckBox checkbox22;
    private CheckBox checkbox23;
    private CheckBox checkbox24;
    private CheckBox checkbox25;
    private CheckBox checkbox26;
    private CheckBox checkbox27;
    private CheckBox checkbox28;
    private CheckBox[] checkBox;
    private String likes;
    private int conut_no;

    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_selectseat);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        initView();
        btn_xuanpian.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getApplicationContext(),RadioBtn.class);

                startActivity(intent);
            }
        });


        btn_xuanzuo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                conut_no = 0;
                for (int i = 0;i<checkBox.length;i++){
                    if (checkBox[i].isChecked()==false){
                        conut_no++;
                    }
                }

                if(conut_no==checkBox.length){
                    Toast.makeText(getApplicationContext(),"您当前尚未选座，请先选座位！",Toast.LENGTH_SHORT).show();
                    txt_xunzuo.setText("您当前尚未选座，请先选座位！");

                }else {
                    likes = "";
                    for (int i = 0;i<checkBox.length;i++){
                        if (checkBox[i].isChecked()==true){
                            likes+= checkBox[i].getText().toString()+"、";
                        }
                    }

                    likes = likes.substring(0,likes.length()-1);




                    AlertDialog.Builder builder = new AlertDialog.Builder(Selectseat.this);
                 //   builder.setIcon(R.drawable.damao);
                    builder.setTitle("温馨提示");
                    builder.setMessage("您当前选择的座位是：" + likes + ",请您再次确认！");
                    builder.setPositiveButton("OKOK", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Toast.makeText(getApplicationContext(),"您当前选择的座位是："+likes,Toast.LENGTH_SHORT).show();
                            txt_xunzuo.setText("您当前选择的座位是："+ likes);
                        }
                    });

                    builder.setNegativeButton("NONO", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            for (int i = 0;i<checkBox.length;i++){
                               checkBox[i].setChecked(false);
                            }
                            Toast.makeText(getApplicationContext(),"您当前尚未选座，请先选座位！"+likes,Toast.LENGTH_SHORT).show();
                            txt_xunzuo.setText("您当前尚未选座，请先选座位！");
                        }
                    });
                    builder.show();

                }



            }
        });


    }

    private void initView() {


        btn_xuanzuo = findViewById(R.id.button_xuanzuo);
        btn_xuanpian = findViewById(R.id.button_xuanpian);
        txt_xunzuo = findViewById(R.id.textView_film);



        checkbox1 = findViewById(R.id.checkBox1);
        checkbox2 = findViewById(R.id.checkBox2);
        checkbox3 = findViewById(R.id.checkBox3);
        checkbox4 = findViewById(R.id.checkBox4);
        checkbox5 = findViewById(R.id.checkBox5);
        checkbox6 = findViewById(R.id.checkBox6);
        checkbox7 = findViewById(R.id.checkBox7);

        checkbox8 = findViewById(R.id.checkBox8);
        checkbox9 = findViewById(R.id.checkBox9);
        checkbox10 = findViewById(R.id.checkBox10);
        checkbox11 = findViewById(R.id.checkBox11);
        checkbox12 = findViewById(R.id.checkBox12);
        checkbox13 = findViewById(R.id.checkBox13);
        checkbox14 = findViewById(R.id.checkBox14);

        checkbox15 = findViewById(R.id.checkBox15);
        checkbox16 = findViewById(R.id.checkBox16);
        checkbox17 = findViewById(R.id.checkBox17);
        checkbox18 = findViewById(R.id.checkBox18);
        checkbox19 = findViewById(R.id.checkBox19);
        checkbox20 = findViewById(R.id.checkBox20);
        checkbox21 = findViewById(R.id.checkBox21);

        checkbox22 = findViewById(R.id.checkBox22);
        checkbox23 = findViewById(R.id.checkBox23);
        checkbox24 = findViewById(R.id.checkBox24);
        checkbox25 = findViewById(R.id.checkBox25);
        checkbox26 = findViewById(R.id.checkBox26);
        checkbox27 = findViewById(R.id.checkBox27);
        checkbox28 = findViewById(R.id.checkBox28);

        checkBox = new CheckBox[]{checkbox1,checkbox2,checkbox3,checkbox4,checkbox5,checkbox6,
                checkbox7,checkbox8,checkbox9,checkbox10,checkbox11,checkbox12,checkbox13,checkbox14,
                checkbox15,checkbox16,checkbox17,checkbox18,checkbox19,checkbox20,checkbox21,
                checkbox22,checkbox23,checkbox24,checkbox25,checkbox26,checkbox27,checkbox28};

    }
}